package org.hilo.boot.core.shiro;

import java.io.Serializable;
import java.util.UUID;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionIdGenerator;

/**
 * 自定义SessionIdGenerator，支持验证SessionId
 * 
 * @see SecurityFormAuthenticationFilter
 * 
 * @author zollty
 * @since 2018年4月3日
 */
public class SecuritySessionIdGenerator implements SessionIdGenerator {

    public Serializable generateId(Session session) {
        String userAgent = SessionEncoder.getUserAgent();
        if (userAgent != null) {
            return SessionEncoder.encode(userAgent);
        }
        return UUID.randomUUID().toString();
    }

}
  
